package com.example.restful.demo.service;

import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author fangjx
 * @date 2021/1/15
 *
 * 为什么有些异常throw出去需要在函数头用throws声明，一些就不用
 * https://www.cnblogs.com/feng9exe/p/9254135.html
 *
 *
 */
@Service
public class DemoService {

    /**
     * 测试测试类加不加@RunWith
     */
    public void testRunWith(){
        System.out.println("RunWith");
    }


    /**
     * RuntimeException 抛出的时候方法上不用声明throws
     * 调用方可以不用处理
     * @param str
     * @return
     */
    public String test1(String str){

        System.out.println("test1");

        if("success".equals(str)){
            return "success";
        }else {
            throw new RuntimeException("出错");
        }
    }

    /**
     * checked Exception 抛出的时候方法上必须声明throws
     * 且调用方必须处理
     * @param str
     * @return
     * @throws IOException
     */
    public String test2(String str) throws IOException {

        System.out.println("test2");

        if("success".equals(str)){
            return "success";
        }else {
            throw new IOException("出错");
        }
    }


    public String testDebug(){
        System.out.println("debug");
        return "debug";
    }




}
